package cn.tuling.simplefactory;

public class AbstractFactoryTest {
    public static void main(String[] args) {
        Factory nikeFactory = new NikeFactory();
        nikeFactory.createHat().wear();
        nikeFactory.createShoe().putOn();

        System.out.println("---------");

        Factory liNingFactory = new LiNingFactory();
        liNingFactory.createHat().wear();
        liNingFactory.createShoe().putOn();
    }
}

/**
 * 耐克的鞋子+帽子是一个产品族
 * 李宁的鞋子+帽子是一个产品族
 */
interface Shoe {
    void putOn();
}

interface Hat {
    void wear();
}

class NikeShoe implements Shoe {
    public NikeShoe() {
        // 你知道我有多难造吗？
    }

    @Override
    public void putOn() {
        System.out.println("穿上耐克的鞋");
    }
}

class LiNingShoe implements Shoe {
    public LiNingShoe() {
        // 你知道我有多难造吗？
    }

    @Override
    public void putOn() {
        System.out.println("穿上李宁的鞋");
    }
}

class NikeHat implements Hat {
    public NikeHat() {
        // 你知道我有多难造吗？
    }

    @Override
    public void wear() {
        System.out.println("戴上耐克的帽子");
    }
}

class LiNingHat implements Hat {
    public LiNingHat() {
        // 你知道我有多难造吗？
    }

    @Override
    public void wear() {
        System.out.println("戴上李宁的帽子");
    }
}

interface Factory {
    Shoe createShoe();

    Hat createHat();
}

class LiNingFactory implements Factory {

    @Override
    public Shoe createShoe() {
        System.out.println("李宁工厂花十年造出一双新鞋");
        return new LiNingShoe();
    }

    @Override
    public Hat createHat() {
        System.out.println("李宁工厂花十年造出一个新帽子");
        return new LiNingHat();
    }
}

class NikeFactory implements Factory {

    @Override
    public Shoe createShoe() {
        System.out.println("耐克工厂花十年造出一只新鞋");
        return new NikeShoe();
    }

    @Override
    public Hat createHat() {
        System.out.println("耐克工厂花十年造出一个帽舌");
        return new NikeHat();
    }
}

